<?xml version="1.0" encoding="utf-8"?>
<taskrunner name="reinstall" version="1.1" date="2013-07-08" maxthreads="1">

  <!-- Script för ominstallation. 
  
  Note:
    First runs  UNINSTALL and then INSTALL
    
    sets global variable main.installation.type = REINSTALL
    before running UNINSTALL the global property install.type = UNINSTALL
    before runnung INSTALL the global property install.type = INSTALL
    
    Change log:
        QC10265 : 2011-08-04 : teriks28
          Removed webex
  
        2013-06-20 : teriks28 : OGB project
          Added new tasks "check.restore.eswdl" for checking if we should backup and restore eSWDL library and store result in global variable.                  
          Added new global variable: "RestoreEswdl" that gets set in task "check.restore.eswdl"
        2013-07-08 : teriks28 : OGB Project
          Added new task "check.permanently.move.of.eswdl.folder" for checking if we should move eswdl library to new location
          Added new task "move.eswdl.to.system.folder" move eswdl library to new location
        2013-08-28 : teriks28 : OGB Project
          Added new task "check.eswdl.dir" for checking if eswdl folder already exist in the new location, if it does we should not move it again.
          Added new task "copy.eswdl.files.to.eswdl.folder" for copy of files from Diagnostic\eswdl to System\eswdl
		2013-11-26: teriks28: ALM 12884 Not possible to install Vida2014A on top of older than previous versions
			Changed tasks "copy.eswdl.files.to.eswdl.folder" and "move.eswdl.to.system.folder"
				Changed condition, added "¤{RestoreEswdl}=true"
				Changed parameter "src" to use new property called "jboss5.target.diagnostics.dir" that point to jboss 5 folder structure
  -->
  
  <includes>
    <file name="vida.install.settings.xml" />
  </includes>

  <parameters>
    <parameter key="request.sqlexpress" value="INPUT#"/>
    <parameter key="request.dice" value="INPUT#"/>
    <parameter key="request.adobereader" value="INPUT#"/>
    <parameter key="request.isoview" value="INPUT#"/>    
    <parameter key="is.vow" value="INPUT#"/>
    <parameter name="request.x64" value="input#"/>
  </parameters>

  <tasks>

    <task name="get.vida.home" typename="@WriteInformation">
      <parameters>
        <parameter name="message" value="vida_home: %{vida_home}"/>
      </parameters>
    </task>

    <task name="set.main.install.type" typename="@SetGlobalProperty">
      <description>
        Sets the global property main.install.type to REINSTALL.
        This value will not change during the reinstallation.
      </description>
      <dependencies list="get.vida.home"/>
      <parameters>
        <parameter name="property.name" value="main.install.type"/>
        <parameter name="property.value" value="REINSTALL"/>
      </parameters>
    </task>

    <!--VIDA's eSWDL handeling changed for VIDA2013C, so if installed VIDA is older then 2013C then no backup of the eSWDL library is done-->
    <task name="check.restore.eswdl" assembly="${a1}" typename="vida.install.eswdl.RestoreESWDLOrNot">
      <description>
        Get installed VIDA version and store it in global variable "installed.vida.version"
      </description>
      <dependencies list="set.main.install.type"/>
      <parameters>
        <parameter name="accessserver.connectionstring" value="${accessserver.cs}"/>
        <parameter name="output.variable" value="RestoreEswdl"/>
      </parameters>
    </task>

    <!--Check if we should move eSWDL libray folder permanently, only move the folder if installed VIDA version is older then 2013D-->
    <task name="check.permanently.move.of.eswdl.folder" assembly="${a1}" typename="vida.install.eswdl.MoveESWDLFolderOrNot">
      <description>
        Check if installed version is older then VIDA2013D
      </description>
      <dependencies list="check.restore.eswdl"/>
      <parameters>
        <parameter name="accessserver.connectionstring" value="${accessserver.cs}"/>
        <parameter name="output.variable" value="permanently.move.eswdl.folder"/>
        <parameter name="destination.directory" value="${target.eswdl.root}"/>
      </parameters>
    </task>

    
    <!--Check if eswdl folder allready exists in target directory-->
    <task name="check.eswdl.dir" typename="@DirectoryExists">
      <dependencies list="check.permanently.move.of.eswdl.folder"/>
      <parameters>
        <parameter name="directory" value="${target.eswdl.root}"/>
        <parameter name="output.value" value="eswdl.dir.exist"/>
      </parameters>
    </task>

    <!--If we are supposted to move eswdl library and the directory %VIDA_HOME%\System\eswdl allready exists we just copy the eswdl files instead of moving the directory-->
	<task name="copy.eswdl.files.to.eswdl.folder" condition="¤{RestoreEswdl}=true AND ¤{permanently.move.eswdl.folder}=true AND ¤{eswdl.dir.exist}=true" typename="@DirectoryCopy">
      <description>
        Copy a directory and files
      </description>
      <dependencies list="check.eswdl.dir"/>
      <parameters>
			<parameter name="src" value="${jboss5.target.diagnostics.dir}\eswdl"/>
        <parameter name="dst" value="${target.eswdl.root}"/>
      </parameters>
    </task>

    <!--Move eSWDL libray folder permanently to VIDA_HOME\System-->
	<task name="move.eswdl.to.system.folder" condition="¤{RestoreEswdl}=true AND ¤{permanently.move.eswdl.folder}=true AND ¤{eswdl.dir.exist}=false" typename="@MoveDirectory">
      <description>
        Moves eSWDL directory to system directory
      </description>
      <dependencies list="check.eswdl.dir,check.permanently.move.of.eswdl.folder"/>
      <parameters>
			<parameter name="src" value="${jboss5.target.diagnostics.dir}\eswdl"/>
        <parameter name="dst" value="${target.eswdl.root}"/>
      </parameters>
	</task>

    <foreach enum="desktop.shortcuts">
      
      <task name="GetTargetArgs" condition="$[desktop.shortcuts:dynamicTarget]=true" allowMultipleInstances="true" typename="@GetTargetArguments" critical="false">
        <description>
          Gets the arguments for each desktop shortcut which have the property dynamicTarget set to true.
          The value will be placed in a global property and then reused when the shortcuts are created again.
        </description>
        
        <dependencies list="set.main.install.type,move.eswdl.to.system.folder"/>
        <parameters>
          <parameter name="directory" value="${desktop}"/>
          <parameter name="filename" value="$[desktop.shortcuts:key].lnk"/>
          <parameter name="output" value="$[desktop.shortcuts:key]"/>
          <parameter name="throwException" value="false"/>
        </parameters>
      </task>
    </foreach>
    
    <!--QC7566 2010-01-22 teriks28: added task for removing unwhanted shortcuts-->
    <foreach enum="removed.desktop.shortcuts">

      <task name="remove.desktop.shortcut" condition="" typename="@DeleteShortcut" allowMultipleInstances="true">
        <description>
          Removes unwhanted shortcuts from the start menu
        </description>
        
        <dependencies list="install,GetTargetArgs"/>
        <parameters>
          <parameter name="folders" value="${vida.programs.folder}"/>
          <parameter name="link.name" value="$[removed.desktop.shortcuts:key]"/>
        </parameters>
      </task>
      
    </foreach>


    <task name="uninstall" critical="false">
      <description>
        Run the installed release's uninstaller
      </description>
      <dependencies list="GetTargetArgs,set.main.install.type,check.restore.eswdl"/>
      <subtasks filename="vida.uninstall.installed.xml">
        <parameters>
          <parameter name="main.inst.type" value="REINSTALL"/>
          <parameter name="RestoreEswdl" value="¤{RestoreEswdl}"/>
        </parameters>
      </subtasks>
    </task>

    <task name="install">
      <dependencies list="uninstall[requireSuccess=false]"/>
      <subtasks filename="vida.doinstall.xml">
        <parameters>
          <parameter name="is.vow" value="${is.vow}"/>
          <parameter name="request.sqlexpress" value="${request.sqlexpress}"/>
          <parameter name="request.dice" value="${request.dice}"/>
          <parameter name="request.adobereader" value="${request.adobereader}"/>
          <parameter name="request.isoview" value="${request.isoview}"/>
          <parameter name="request.x64" value="${request.x64}"/>
        </parameters>
      </subtasks>
    </task>

    <foreach enum="desktop.shortcuts">

      <task name="UpdateTargetArgs" condition="$[desktop.shortcuts:dynamicTarget]=true AND ¤{KeepLocalDb}=true" allowMultipleInstances="true" typename="@CreateDesktopShortcut" critical="false">
        <description>
          Gets the arguments for each desktop shortcut which have the property dynamicTarget set to true.
          The value will be placed in a global property and then reused when the shortcuts are created again.
        </description>
        <dependencies list="install,GetTargetArgs"/>
          <parameters>
            <parameter name="folders" value="$[desktop.shortcuts:folders]"/>
            <parameter name="target.path" value="$[desktop.shortcuts:target]"/>
            <parameter name="arguments" value="¤{$[desktop.shortcuts:key]}"/>
            <parameter name="link.name" value="$[desktop.shortcuts:key]"/>
            <parameter name="icon.fullpath" value="$[desktop.shortcuts:icon]"/>
            <parameter name="workingdirectory" value="$[desktop.shortcuts:workingdirectory]"/>
          </parameters>
        </task>
      
    </foreach>

  </tasks>

  <events>
    <event name="ON_FINISH_OK">
      <subtasks filename="vida.finish.ok.xml">
      </subtasks>
    </event>

    <event name="ON_FINISH_FAILED">
      <subtasks filename="vida.finish.nok.xml">
      </subtasks>
    </event>
  </events>
  
</taskrunner>